package com.ruoyi.web.controller.order;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.order.domain.BzOrder;
import com.ruoyi.order.service.IBzOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单明细Controller
 * 
 * @author ericyu
 * @date 2021-11-25
 */
@RestController
@RequestMapping("/order/orderlist")
public class BzOrderController extends BaseController
{
    @Autowired
    private IBzOrderService bzOrderService;

    /**
     * 查询订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderlist:list')")
    @GetMapping("/list")
    public TableDataInfo list(BzOrder bzOrder)
    {
        startPage();
        List<BzOrder> list = bzOrderService.selectBzOrderList(bzOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderlist:export')")
    @Log(title = "订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BzOrder bzOrder)
    {
        List<BzOrder> list = bzOrderService.selectBzOrderList(bzOrder);
        ExcelUtil<BzOrder> util = new ExcelUtil<BzOrder>(BzOrder.class);
        util.exportExcel(response, list, "订单明细数据");
    }

    /**
     * 获取订单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderlist:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return AjaxResult.success(bzOrderService.selectBzOrderByOrderId(orderId));
    }

    /**
     * 新增订单明细
     */
    @PreAuthorize("@ss.hasPermi('order:orderlist:add')")
    @Log(title = "订单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BzOrder bzOrder)
    {
        return toAjax(bzOrderService.insertBzOrder(bzOrder));
    }

    /**
     * 修改订单明细
     */
    @PreAuthorize("@ss.hasPermi('order:orderlist:edit')")
    @Log(title = "订单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BzOrder bzOrder)
    {
        return toAjax(bzOrderService.updateBzOrder(bzOrder));
    }

    /**
     * 删除订单明细
     */
    @PreAuthorize("@ss.hasPermi('order:orderlist:remove')")
    @Log(title = "订单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(bzOrderService.deleteBzOrderByOrderIds(orderIds));
    }
}
